/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Thing;

import Core.Status;
import Core.Vector2;
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author THINH
 */
public abstract class Thing {
    
    //field
    
    public Status status;
    public boolean isLive = true;
    protected Vector2 vel = null;
    protected Sprite sprite;
    protected boolean colision = false;
    public boolean isEnableGravity = false;
    
    //constructor
    public Thing(){
        vel = Vector2.Zero();
        status = new Status();
    }
    
    public Thing(String pathImage, int frameWidth, int frameHeight, int[]frameSequence){
        vel = Vector2.Zero();        
        status = new Status();
        try{
            Image img = Image.createImage(pathImage);
            sprite = new Sprite(img, frameWidth, frameHeight);
            if(frameSequence != null)
                sprite.setFrameSequence(frameSequence);
            sprite.setPosition(0, 0);
            sprite.setVisible(true);
        }
        //catch(IOException ioe){
            
        //}
        catch(Exception e){
            e.printStackTrace();
        }
        finally{
            
        }
    
    }
    
    // main func
    public void update(){
        sprite.move((int)vel.x, (int)vel.y);
        sprite.nextFrame();
        
    }   
    
    // position func
    public Vector2 getVelocity(){
        return vel;        
    }
    public void setVelocity(Vector2 vec){
        vel = vec;     
    }
    public Vector2 getPos(){
        return new Vector2(sprite.getX(),sprite.getY());
    }
    public int getX(){
        return sprite.getX();
    }
    public int getY(){
        return sprite.getY();
    }
    public void setPos(Vector2 newPoint){
        sprite.setPosition((int)newPoint.x, (int)newPoint.y);
    }
    public void setPos(float x, float y){
        sprite.setPosition((int)x, (int)y);
    }
    public int getHeight(){
        return sprite.getHeight();
    }
    public int getWidth(){
        return sprite.getWidth();
    }
    // sprite func
    public Sprite getSprite(){
        return sprite;
    }
    
    public void setSprite(Sprite newSprite){
        sprite = newSprite;
    }
    
    
}
